package com.mall.admin.controller;


import com.mall.admin.service.SmsHomeAdvertiseService;
import com.mall.commons.utils.R;
import com.mall.domain.SmsHomeAdvertise;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/home/advertise")
public class SmsHomeAdvertiseController {

    @Autowired
    private SmsHomeAdvertiseService smsHomeAdvertiseService;


    /**
     * 分页条件查询
     */
    @GetMapping("/list")
    public R findByPage(String endTime,String name, Integer pageNum, Integer pageSize, Integer type) {
        return smsHomeAdvertiseService.findByPage(endTime,name,pageNum,pageSize,type);
    }

    //添加
    @PostMapping("/create")
    public R addCreate(@RequestBody SmsHomeAdvertise advertise) {
        return smsHomeAdvertiseService.addCreate(advertise);
    }

    //批量删除
    @PostMapping("/delete")
    public R delete(@RequestParam("ids") List<Long> ids) {
        return smsHomeAdvertiseService.delete(ids);
    }

    //修改状态
    @PostMapping("/update/status/{id}")
    public R updateStatus(@PathVariable Long id,Integer status) {
        return smsHomeAdvertiseService.updateStatus(id,status);
    }

    //修改广告
    @PostMapping("/update/{id}")
    public R updateAdvertise(@RequestBody SmsHomeAdvertise advertise,@PathVariable Long id) {
        return smsHomeAdvertiseService.updateAdvertise(advertise,id);
    }

    //获取广告详情
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id) {
        SmsHomeAdvertise smsHomeAdvertise = smsHomeAdvertiseService.findById(id);
        return R.success("回显成功",smsHomeAdvertise);
    }


}
